package exerciseFrames;

import java.util.ArrayList;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

import constants.Constants;

import person.PersonRecorder;
import exerciseRecord.ExerciseRecorder;

public class ExerciseRecordFrame extends JFrame {
	private JScrollPane panel;
	private JTextArea textArea;

	public ExerciseRecordFrame() {
		this.setBackground(Constants.PANEL_BACKGROUND_COLOR);
		getContentPane().setLayout(null);
		this.setSize(500, 700);
		this.setVisible(true);

		textArea = new JTextArea();
		textArea.setBounds(0, 0, 480, 660);
		
		panel = new JScrollPane(textArea);
		panel.setBackground(Constants.PANEL_BACKGROUND_COLOR);
		panel.setBounds(0, 0, 480, 660);
		getContentPane().add(panel);
	}

	public void writeExerciseRecord(PersonRecorder personRecorder) {
		ArrayList<ExerciseRecorder> exerciseRecorderArray = personRecorder.getExerciseRecorderArray();
		
		textArea.setText("");
		
		for (int i = 0; i < exerciseRecorderArray.size(); i++) {
			if(exerciseRecorderArray.get(i).getDate() != null) {
			textArea.append("Date:"+exerciseRecorderArray.get(i).getDate()+ "\n");
			for (int j = 0; j < exerciseRecorderArray.get(i).getExerciseArray().size(); j++) {
				textArea.append("Type\tSpeed\tTime\tWeight\tCount\n");
				textArea.append(exerciseRecorderArray.get(i).getExerciseArray().get(j).getExerciseType()+"\t");
				textArea.append(exerciseRecorderArray.get(i).getExerciseArray().get(j).getSpeed()+"\t");
				textArea.append(exerciseRecorderArray.get(i).getExerciseArray().get(j).getTime()+"\t");
				textArea.append(exerciseRecorderArray.get(i).getExerciseArray().get(j).getWeight()+"\t");
				textArea.append(exerciseRecorderArray.get(i).getExerciseArray().get(j).getCount()+"\n\n");
			}
			textArea.append("----------------------------------------------------------------------\n");
			}
		}

		this.setVisible(true);
	}

}
